<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page language="java" import="java.lang.*" %>
<%@ page import = "java.sql.SQLException" %>
<%@ page import = "com.seniorproject.aims.*" %>
<%@ page import = "java.util.List" %>
<%@page import="java.util.ArrayList"%>
<%@ page import = "java.util.Properties" %>
<%@ page import = "javax.servlet.ServletContext" %>
<%@ page import = "java.io.File" %>
<%@ page import = "java.io.InputStream" %>
<%@ page import = "java.sql.PreparedStatement" %>
<%@page import="java.util.regex.Matcher"%>
<%@page import="java.util.regex.Pattern"%>

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>Modify Category</title>
	<link rel="stylesheet" type="text/css" href="css/stylev2.css" />
	<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
	
	<style type="text/css">
		a {
	      text-decoration:none;
	   }
	</style>
	
	<script>
		function deleteButton(id) {
			var catName = (document.getElementById('categoryName' + id)).innerHTML;
			var CategoryIdDelete = (document.getElementById('CategoryIdDelete' + id)).value;
			var Credit_category = (document.getElementById('Credit_category' + id)).innerHTML;
			
			
			
			
			if (confirm("คุณต้องการจะลบใช่หรือไม่ ?"+catName+Credit_category) == true) {
				/* AJAX */
				var xmlhttp;
				
				if(window.XMLHttpRequest) {
					// code for IE7+, Firefox, Chrome, Opera, Safari
					xmlhttp = new XMLHttpRequest();
				}
				else {
					// code for IE6, IE5
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
				
				xmlhttp.onreadystatechange = function() {
					if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
						window.location.reload();
						alert("ลบข้อมูลหมวดวิชาสำเร็จ");////////test///////
					}
				}
				
				xmlhttp.open("POST", "curriculum_delete_category_modified.jsp?CategoryIdDelete="+CategoryIdDelete, true);
				xmlhttp.send();
		    } else {

		    }
			
		}	
		
		function search_name(courseid) {
			if($('#namelist').find('option').length > 0) {
				
				$('#namelist').find('option').remove();
			}
			if(courseid.length>2) {
				
				/* AJAX */
				var xmlhttp;
				
				if(window.XMLHttpRequest) {
					// code for IE7+, Firefox, Chrome, Opera, Safari
					xmlhttp = new XMLHttpRequest();
				}
				else {
					// code for IE6, IE5
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
				
				xmlhttp.onreadystatechange = function() {
					if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
						
						
						var jsonObj = JSON.parse(xmlhttp.responseText);
						
						if(jsonObj.length == 0) {
							// no data
						}
						else{
							
							for(i in jsonObj) {
								var text = jsonObj[i].courseId+"  , "+jsonObj[i].courseNameEN+" , "+jsonObj[i].credit+" ( "+jsonObj[i].lecture+" "+jsonObj[i].lab+" "+jsonObj[i].selfLearn+" ) , "+jsonObj[i].details;
								var option = '<option value="'+text+'" >';
								$('#namelist').append(option);								
							}
							var result = document.getElementById("search_box").value;	
							
						}
					}
					
				}
				
				xmlhttp.open("POST", "curriculum_search_course_name.jsp?courseid="+courseid, true);
				xmlhttp.send();
				
			}	
		}

	</script>
	
</head>
<body>

<%
	//Get session
	String strUser = String.valueOf(session.getAttribute("sUser"));
	HttpSession htp_session = request.getSession();
			
	if (htp_session == null || htp_session.getAttribute("sUser") == null) {
	    // Forward the control to login.jsp if authentication fails or session expires
	    request.getRequestDispatcher("/login.jsp").forward(request,
	        response);
	}
	
	if("admin".equals(htp_session.getAttribute("sUser"))){%>
	<script>alert("This user dont have PERMISSION to access this zone.");</script>
	<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=admin_home.jsp"> 	
	<%}
	
	//GET PERMISSION
		String name = String.valueOf(session.getAttribute("name"));
		String surname = String.valueOf(session.getAttribute("surname"));
		String role_name = String.valueOf(session.getAttribute("curriculum_role"));
		
		String department_id = String.valueOf(session.getAttribute("department_id"));
				
		System.out.println("name : " + name);///////////////////////////////
		System.out.println("department_id : " + department_id);/////////////////////////
		
		List<String> system_name = new ArrayList<String>();
		
		Permission permission = new Permission(strUser,name);
		permission.setCurriculumCreate(Boolean.valueOf(String.valueOf(session.getAttribute("curriculum_create"))));
		permission.setCurriculumDelete(Boolean.valueOf(String.valueOf(session.getAttribute("curriculum_delete"))));
		permission.setCurriculumRead(Boolean.valueOf(String.valueOf(session.getAttribute("curriculum_read"))));
		permission.setCurriculumUpdate(Boolean.valueOf(String.valueOf(session.getAttribute("curriculum_update"))));
		
		String permiss = "";
		if(permission.getCurriculumCreate()) {
			permiss = permiss + "Add";
		}
		if(permission.getCurriculumUpdate()) {
			if("".equals(permiss)) {
				permiss = permiss + "Edit";
			} else {
				permiss = permiss + " Edit";
			}
		}
		if(permission.getCurriculumRead()) {
			if("".equals(permiss)) {
				permiss = permiss + "Read";
			} else {
				permiss = permiss + " Read";
			}
		}
		if(permission.getCurriculumDelete()) {
			if("".equals(permiss)) {
				permiss = permiss + "Delete";
			} else {
				permiss = permiss + " Delete";
			}
		}

		//check permission
			if(!permission.getCurriculumCreate()){%>
				<script>alert("This user dont have PERMISSION to access this zone.");</script>
				<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=curriculum_home.jsp"> 	
			<%}
		
	//set Database Connection
		String hostProps = "";
		String usernameProps  = "";
		String passwordProps  = "";
		String databaseProps = "";
	
		try {
			//get current path
			ServletContext servletContext = request.getSession().getServletContext();
			
			InputStream input = servletContext.getResourceAsStream("/properties/connectDB.properties");
			Properties props = new Properties();
			
			props.load(input);

			hostProps  = props.getProperty("host");
			usernameProps  = props.getProperty("username");
			passwordProps  = props.getProperty("password");
			databaseProps = props.getProperty("database");
		} catch (Exception e) { 
			out.println(e);  
		}
		
		System.out.println("hostProperties : "+hostProps);////////////////try/////////////////
		System.out.println("usernameProperties : "+usernameProps);////////////////try/////////////////
		System.out.println("passwordProperties : "+passwordProps);////////////////try/////////////////
		System.out.println("databaseProperties : "+databaseProps);////////////////try/////////////////
		// connect database
		Connection connect = null;		
		try {
			Class.forName("com.mysql.jdbc.Driver");
		
			connect =  DriverManager.getConnection("jdbc:mysql://" + hostProps  + "/" + databaseProps +
					"?user=" + usernameProps  + "&password=" + passwordProps + "&characterEncoding=tis620");//////"&characterEncoding=tis620" Encoding Thai);
		
			if(connect != null){
				System.out.println("Database Connect Sucesses.");
			} else {
				System.out.println("Database Connect Failed.");	
			}

		} catch (Exception e) {
			out.println(e.getMessage());
			e.printStackTrace();
		}

		String CurriculumId_cat = String.valueOf(session.getAttribute("CurriculumId_cat"));//Previous modified curriculum
		int CurriculumId = Integer.parseInt(CurriculumId_cat);
		System.out.println("CID: "+CurriculumId);	
		
		String CCredit = String.valueOf(session.getAttribute("CCredit"));
		int Credit_cur = Integer.parseInt(CCredit);
		System.out.println("CCredit: "+Credit_cur);		
		
		String CurriculumId_curri = String.valueOf(session.getAttribute("CurriculumId_curri"));//Current modified curriculum
		int CurriculumIdOLD = Integer.parseInt(CurriculumId_curri);
		System.out.println("CID: "+CurriculumId);	
		
		String OHCE = String.valueOf(session.getAttribute("OHCE"));
		String tempOHCE = OHCE;
		System.out.println("OHCE: "+OHCE);	
		
		String ONEC = String.valueOf(session.getAttribute("ONEC"));
		String tempONEC = ONEC;
		System.out.println("ONEC: "+ONEC);	
		
		String EngApp = String.valueOf(session.getAttribute("EngApp"));
		String tempEngApp = EngApp;
		System.out.println("EngApp: "+EngApp);	
		
		String checker2 = String.valueOf(session.getAttribute("checker"));
		String tempchecker2 = checker2;
		System.out.println("tempchecker2: "+tempchecker2);	
		
		String credit = String.valueOf(session.getAttribute("value"));
		int creditValue = Integer.parseInt(credit);
		System.out.println("creditValue: "+creditValue);
		
		String checker4 ="none";
		
		/*Find Intern Course in DB*/
		List<Course> course = new ArrayList<Course>();
		
		try{
			ResultSet rs_cour = connect.createStatement().executeQuery("SELECT `course_id` ,`group_id`,`curriculum_id`,`credit`, `course_name_th`, `course_name_en`"
					+ " FROM course "
					+ " WHERE curriculum_id="+ CurriculumIdOLD +" AND group_id="+ 0 );
			
			while(rs_cour.next()) {
				Course cour = new Course();
				
				cour.setCourseId(rs_cour.getString("course_id"));
				cour.setCredit(rs_cour.getInt("credit"));
				cour.setCourseNameEN(rs_cour.getString("course_name_en"));
				cour.setCourseNameTH(rs_cour.getString("course_name_th"));
				course.add(cour);
				
				System.out.println("course.size(): "+course.size());	
				
			}
			
		}catch (SQLException e) {
			e.printStackTrace();
		}
		
		
		
		/*Find Category in DB*/
		List<Category> category = new ArrayList<Category>();
		List<Curriculum> curriculum = new ArrayList<Curriculum>();
		try{
			ResultSet rs_cat = connect.createStatement().executeQuery("SELECT `category_id`, C.credit, S.category_name, C.curriculum_id, S.curriculum_id, S.credit ,C.ohce_approved,C.onec_approved"
								+ " FROM subject_category S, curriculum C " 
								+ " WHERE C.curriculum_id = S.curriculum_id AND S.curriculum_id = " + CurriculumId + ""
								+ " ORDER BY category_id");
			
			while(rs_cat.next()) {
				Category cate = new Category();
				
				cate.setCategoryId(Integer.parseInt(rs_cat.getString("category_id")));	
				cate.setCategoryName(rs_cat.getString("S.category_name"));
				cate.setCurriculumId(Integer.parseInt(rs_cat.getString("S.curriculum_id")));				
				cate.setCredit(Integer.parseInt(rs_cat.getString("S.credit")));
				
				category.add(cate);
				
				Curriculum curri = new Curriculum();
				
				curri.setCurriculumId(Integer.parseInt(rs_cat.getString("C.curriculum_id")));				
				curri.setCredit(Integer.parseInt(rs_cat.getString("C.credit")));	
				curri.setOHCE(rs_cat.getString("C.ohce_approved"));
				curri.setONEC(rs_cat.getString("C.onec_approved"));
				
				curriculum.add(curri);
			}
			
		}catch (SQLException e) {
			e.printStackTrace();
		}
		
		String button = String.valueOf(session.getAttribute("button1"));
		System.out.println("button: "+button);/////////////////////////////////////
		
		String credit_group = String.valueOf(session.getAttribute("Credit_group_cat"));
		System.out.println("flag: "+credit_group);////////////////////////////////////////
		
		String OLDdata = String.valueOf(session.getAttribute("OLDdata"));
		System.out.println("OLDdata: "+OLDdata);
		
////////////////// START ADDING OLD INFORMATION ////////////////////////		
		if(OLDdata.equals("TRUE")){
			
//////////////////////////ADD CATEGORY FROM OLD CURRICULUM////////////////////////////////////////////////////

		try {
	//PHASE 1 ADD CATEGORY
			System.out.println("ENTER PHASE 1 ADD CATEGORY");
			List<Category> category3 = new ArrayList<Category>();
			
			ResultSet rs_CATEGORY = connect.createStatement().executeQuery("SELECT `category_id`, `category_name`, `credit`"         
					+ " FROM subject_category"
					+ " WHERE curriculum_id="+ CurriculumId
					+ " ORDER BY category_id" );
			
			//Query Previous Information from DB
			while(rs_CATEGORY.next()) {
				
				Category cat3 = new Category();
				
				cat3.setCategoryId(rs_CATEGORY.getInt("category_id"));
				cat3.setCategoryName(rs_CATEGORY.getString("category_name"));
				cat3.setCredit(rs_CATEGORY.getInt("credit"));	
				
				category3.add(cat3);
				System.out.println("category3.size=  "+category3.size());
				
			}
			//When Query is ended, Insert into DB
				for(int i=0; i<category3.size(); i++){
					System.out.println("///////////////////////////////////////////////////");
					System.out.println("CATEGORY START !!!!");
					System.out.println("///////////////////////////////////////////////////");
					
					String tempCategoryName = category3.get(i).getCategoryName();
					System.out.println("tempCategoryName=  "+tempCategoryName);
					
					int tempCurriculumId = CurriculumIdOLD; //current curriculumId
					System.out.println("tempCurriculumId=  "+tempCurriculumId);
					
					int tempCreditCategory = category3.get(i).getCredit();
					System.out.println("tempCreditCategory=  "+tempCreditCategory);
					
				//Add information 
					PreparedStatement pstmt = connect.prepareStatement("INSERT INTO `subject_category`( `category_name`, `curriculum_id`, `credit`) "
							+ " VALUES ('"+ tempCategoryName +"',"+ tempCurriculumId +","+ tempCreditCategory +")" , Statement.RETURN_GENERATED_KEYS);			
					pstmt.executeUpdate();
					ResultSet keys = pstmt.getGeneratedKeys();    
					keys.next();  					//////////////// KEYS 1 ///////////////
					int key = keys.getInt(1);		//////////////// NEW CATEGORY ID = KEY 1 /////////////////////
					System.out.println("key=  "+key);
					int keyOLD = category3.get(i).getCategoryId(); //////////////// OLD CATEGORY ID = KEY 1 /////////////////////
					System.out.println("keyOLD=  "+keyOLD);
					
					String sql_subject_category = "INSERT INTO `subject_category`( `category_name`, `curriculum_id`, `credit`) "
							+ " VALUES ('"+ tempCategoryName +"',"+ tempCurriculumId +","+ tempCreditCategory +")";
					/* Log file */
					String log_user = strUser+" add subject_category";
					Log.writeUserFile(log_user);
					Log.writeUserFile(sql_subject_category);
					
				//Confirmation Text 
				System.out.println("OLD CATEGORY ID= "+keyOLD+"  CATEGORY ID= "+key+"  Category Name= "+tempCategoryName+" has been ADDED!");
					
					
//////////////////////////ADD GROUP FROM OLD CURRICULUM////////////////////////////////////////////////////		
			//PHASE 2 ADD GROUP		
					System.out.println("///////////////////////////////////////////////////");
					System.out.println("ENTER PHASE 2 ADD GROUP");
					List<Group> group3 = new ArrayList<Group>();
					//List<Category> category3 = new ArrayList<Category>();
					
					ResultSet rs_GROUP = connect.createStatement().executeQuery("SELECT `group_id`, `group_name`, `curriculum_id`, `category_id`, `credit` "
							+ " FROM subject_group"
							+ " WHERE curriculum_id="+ CurriculumId +" AND category_id="+keyOLD    ////////Check curriculum = 5 and category = 6
							+ " ORDER BY category_id" );
					
					//Query Previous Information from DB
					while(rs_GROUP.next()) {
						
						Group gro3 = new Group();
						
						gro3.setGroupId(rs_GROUP.getInt("group_id"));
						gro3.setGroupName(rs_GROUP.getString("group_name"));
						gro3.setCategoryId(rs_GROUP.getInt("category_id")); // ex. 6,7
						gro3.setCredit(rs_GROUP.getInt("credit"));
						
						group3.add(gro3);
						System.out.println("group3.size=  "+group3.size());
						
					}
					
					//When Query is ended, Insert into DB
					for(int j=0; j<group3.size(); j++){
						System.out.println("///////////////////////////////////////////////////");
						System.out.println("GROUP START !!!!");
						System.out.println("///////////////////////////////////////////////////");
						
						String tempGroupName = group3.get(j).getGroupName();
						System.out.println("tempGroupName=  "+tempGroupName);
						
						int tempCategoryId2 = key; //////////////// NEW CATEGORY ID /////////////////////
						System.out.println("tempCategoryId2=  "+tempCategoryId2);
						
						int tempCreditGroup = group3.get(j).getCredit();
						System.out.println("tempCreditGroup=  "+tempCreditGroup);
						
					//Add information 
						PreparedStatement pstmt2 = connect.prepareStatement("INSERT INTO `subject_group`( `group_name`, `curriculum_id`, `category_id`, `credit`) "
								+ " VALUES ('"+ tempGroupName +"',"+ tempCurriculumId +","+ tempCategoryId2 +","+ tempCreditGroup +")" , Statement.RETURN_GENERATED_KEYS);			
						pstmt2.executeUpdate();
						
						ResultSet keys2 = pstmt2.getGeneratedKeys();    
						keys2.next();  					//////////////// KEYS 2 ///////////////
						int key2 = keys2.getInt(1);		//////////////// NEW GROUP ID = KEY2/////////////////////
						System.out.println("key2=  "+key2);					
						int key2OLD = group3.get(j).getGroupId(); //////////////// OLD GROUP ID = KEY 2 /////////////////////
						System.out.println("key2OLD=  "+key2OLD);
						
						String sql_subject_group = "INSERT INTO `subject_group`( `group_name`, `curriculum_id`, `category_id`, `credit`) "
								+ " VALUES ('"+ tempGroupName +"',"+ tempCurriculumId +","+ tempCategoryId2 +","+ tempCreditGroup +")";
						/* Log file */
						String log_user2 = strUser+" add subject_group";
						Log.writeUserFile(log_user2);
						Log.writeUserFile(sql_subject_group);
						
						//Confirmation Text 
						System.out.println("GROUP ID= "+key2+"  Group Name= "+tempGroupName+" Category ID= "+tempCategoryId2+"  has been ADDED!");
						
//////////////////////////ADD COURSE FROM OLD CURRICULUM ////////////////////////////////////////////////////		
				//PHASE 3 ADD COURSE		
						System.out.println("///////////////////////////////////////////////////");
						System.out.println("ENTER PHASE 3 ADD COURSE");
						List<Course> course3 = new ArrayList<Course>();
						
						ResultSet rs_COURSE = connect.createStatement().executeQuery("SELECT `index`, `course_id`, `group_id`, `curriculum_id`, `course_name_th`, `course_name_en`, `credit`, "          
						+"`lecture_hour`, `lab_hour`, `self_learning_hour`, `detail`, `ohce_approved`, `onec_approved`, `curriculum_EngApp` "
						+ " FROM course "
						+ " WHERE curriculum_id="+ CurriculumId+" AND group_id="+ key2OLD);		
						
						//Query Previous Information from DB
						while(rs_COURSE.next()) {
							Course cou3 = new Course();
							
							cou3.setCourseId(rs_COURSE.getString("course_id"));
							cou3.setGroupId(rs_COURSE.getInt("group_id"));
							cou3.setCurriculumId(rs_COURSE.getInt("curriculum_id"));
							cou3.setCourseNameTH(rs_COURSE.getString("course_name_th"));
							cou3.setCourseNameEN(rs_COURSE.getString("course_name_en"));
							cou3.setCredit(rs_COURSE.getInt("credit"));		
							cou3.setLecture(rs_COURSE.getInt("lecture_hour"));
							cou3.setLab(rs_COURSE.getInt("lab_hour"));
							cou3.setSelfLearn(rs_COURSE.getInt("self_learning_hour"));
							cou3.setDetails(rs_COURSE.getString("detail"));
							cou3.setOHCE(rs_COURSE.getString("ohce_approved"));
							cou3.setONEC(rs_COURSE.getString("onec_approved"));
							cou3.setcurriculum_EngApp(rs_COURSE.getString("curriculum_EngApp"));
							
							course3.add(cou3);
							System.out.println("course3.size=  "+course3.size());
						}	
							//When Query is ended, Insert into DB
							for(int k=0; k<course3.size(); k++){
								//temp
								String tempCourseOHCE = null;
								String tempCourseONEC = null;
								String tempCourseEngApp = null;
								
								
								
								System.out.println("///////////////////////////////////////////////////");
								System.out.println("COURSE START !!!!");
								System.out.println("///////////////////////////////////////////////////");
								
								String tempCourseID = course3.get(k).getCourseId();
								System.out.println("tempCourseID=  "+tempCourseID);
								
								String tempCourseNameEN = course3.get(k).getCourseNameEN();
								System.out.println("tempCourseNameEN=  "+tempCourseNameEN);
								
								String tempCourseNameTH = course3.get(k).getCourseNameTH();
								System.out.println("tempCourseNameTH=  "+tempCourseNameTH);
								
								int tempCreditCourse = course3.get(k).getCredit();
								System.out.println("tempCreditCourse=  "+tempCreditCourse);
								
								int tempLecture = course3.get(k).getLecture();
								System.out.println("tempLecture=  "+tempLecture);
								
								int tempLab = course3.get(k).getLab();
								System.out.println("tempLab=  "+tempLab);
								
								int tempSelfLearn = course3.get(k).getSelfLearn();
								System.out.println("tempSelfLearn=  "+tempSelfLearn);
								
								String tempDetails = course3.get(k).getDetails();
								System.out.println("tempDetails=  "+tempDetails);
								
								int tempCurriculumID = CurriculumIdOLD;
								System.out.println("tempCurriculumID=  "+tempCurriculumID);
								
								int tempGroupID = key2;
								System.out.println("tempGroupID=  "+tempGroupID);
								
								String tempCurriculum_EngApp = course3.get(k).getcurriculum_EngApp();
								System.out.println("tempCurriculum_EngApp=  "+tempCurriculum_EngApp);	
								
						////////////////////////////////////////////////////////////////////////////
						
								//if input was null				
								if(OHCE.equals("null")){
									tempOHCE = "null";
									System.out.println("tempOHCE "+tempOHCE);
								}else{
									tempOHCE =  OHCE;
									System.out.println("tempOHCE "+tempOHCE);
								}
								
								//if input was null
								if(ONEC.equals("null")){
									tempONEC = "null";
									System.out.println("tempONEC "+tempONEC);
								}else{
									tempONEC = ONEC  ;
									System.out.println("tempONEC "+tempONEC);
								}
								/*// ENGAPP
								if("null".equals(tempCurriculum_EngApp)){
									
									tempCourseEngApp = "null" ;
									System.out.println("tempCourseEngApp "+tempCourseEngApp);
								
								}else{							
									tempCourseEngApp = tempCurriculum_EngApp;
									System.out.println("tempCourseEngApp "+tempCourseEngApp);
								
								}*/
								
						////////////////////////////////////////////////////////////////////////////									
								
								
								//Add information 
								PreparedStatement pstmt3 = connect.prepareStatement("INSERT INTO  `course`(`course_id`, `group_id`, `curriculum_id`, `course_name_th`, `course_name_en`, `credit`, "
										+ "`lecture_hour`, `lab_hour`, `self_learning_hour`, `detail`, `ohce_approved`, `onec_approved`, `curriculum_EngApp`)"
										+ " VALUES ('"+ tempCourseID +"', "+ key2 +", "+ tempCurriculumID +",'"+ tempCourseNameTH + "', '"+ tempCourseNameEN +"', "+ tempCreditCourse +", "
										+ "	"+ tempLecture +", "+ tempLab +", "+ tempSelfLearn +", '"+ tempDetails +"', "+ tempOHCE +", "+ tempONEC +", "+ tempCourseEngApp +")" , Statement.RETURN_GENERATED_KEYS);			
								pstmt3.executeUpdate();
								
								ResultSet keys3 = pstmt3.getGeneratedKeys();    
								keys3.next();  					//////////////// KEYS 3 ///////////////
								int key3 = keys3.getInt(1);		//////////////// NEW INDEX ID = KEY 3 /////////////////////
								System.out.println("key3=  "+key3);		
								
								String sql_course = "INSERT INTO  `course`(`course_id`, `group_id`, `curriculum_id`, `course_name_th`, `course_name_en`, `credit`, "
										+ "`lecture_hour`, `lab_hour`, `self_learning_hour`, `detail`, `ohce_approved`, `onec_approved`, `curriculum_EngApp`)"
										+ " VALUES ('"+ tempCourseID +"', "+ key2 +", "+ tempCurriculumID +",'"+ tempCourseNameTH + "', '"+ tempCourseNameEN +"', "+ tempCreditCourse +", "
										+ "	"+ tempLecture +", "+ tempLab +", "+ tempSelfLearn +", '"+ tempDetails +"', "+ tempOHCE +", "+ tempONEC +", "+ tempCourseEngApp +")";
								
								/* Log file */
								String log_user3 = strUser+" add course";
								Log.writeUserFile(log_user3);
								Log.writeUserFile(sql_course);
								
								
								//Confirmation Text 
								System.out.println("INDEX ID= "+key3+"  Course Name EN= "+tempCourseNameEN+" Group ID= "+tempGroupID+"  has been ADDED!");
								System.out.println("OHCE= "+OHCE+"  ONEC= "+ONEC+" tempCurriculum_EngApp= "+tempCurriculum_EngApp+"  has been ADDED!");	
								System.out.println("-");	
								
							}//for K Course
							
						}//for J Group

					}	//for I Category	
			
				session.setAttribute("OLDdata", "FALSE");// add previous info
			
			} catch (SQLException e) {
				System.out.println("Error At Phase 1 Add CurriID:"+e);
				e.printStackTrace();
			}
		}
////////////////////////////QUERY CURRENT CURRICULUM /////////////////////////////////

		/*Find Category in DB*/
		List<Category> category4 = new ArrayList<Category>();
		List<Curriculum> curriculum4 = new ArrayList<Curriculum>();
		try{
			ResultSet rs_cat4 = connect.createStatement().executeQuery("SELECT `category_id`, C.credit, S.category_name, C.curriculum_id, S.curriculum_id, S.credit ,C.ohce_approved,C.onec_approved, C.curriculum_EngApp"
								+ " FROM subject_category S, curriculum C " 
								+ " WHERE C.curriculum_id = S.curriculum_id AND S.curriculum_id = " + CurriculumIdOLD + ""
								+ " ORDER BY category_id");
			
			while(rs_cat4.next()) {
				Category cate = new Category();
				
				cate.setCategoryId(Integer.parseInt(rs_cat4.getString("category_id")));	
				cate.setCategoryName(rs_cat4.getString("S.category_name"));
				cate.setCurriculumId(Integer.parseInt(rs_cat4.getString("S.curriculum_id")));				
				cate.setCredit(Integer.parseInt(rs_cat4.getString("S.credit")));
				
				category4.add(cate);
				
				Curriculum curri = new Curriculum();
				
				curri.setCurriculumId(Integer.parseInt(rs_cat4.getString("C.curriculum_id")));				
				curri.setCredit(Integer.parseInt(rs_cat4.getString("C.credit")));	
				curri.setOHCE(rs_cat4.getString("C.ohce_approved"));
				curri.setONEC(rs_cat4.getString("C.onec_approved"));
				curri.setEngApp(rs_cat4.getString("C.curriculum_EngApp"));
				curriculum4.add(curri);
			}
			
		}catch (SQLException e) {
			e.printStackTrace();
		}

%>
<div id="page-wrap">
		<div id="inside">
			<table border="0">
				<tr style="font-size:24px">
					<td width="600" height="100" style= "background-color: #273b80;border: 0px ;padding: 0px; 0px;" >
						<div id="header_banner-2"></div>
					</td>
					<td width="680" height="100" style= "background-color: #273b80;border: 0px;padding: 0px; 0px;" >
						<p align="right" ><label><font size="4" color="#FFFFFF">  username : <%=strUser %>&nbsp;&nbsp;</font></label></p>
						<a href="logout.jsp"><p align="right"><label style="cursor: pointer;"><font size="3" color="#ffffff">log out &nbsp;</font></label></p></a>
					</td>							
				</tr>
			</table>
		<%
			////////////////// Header ///////////////////
		%>	
				<div id="main-content-2">
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<label><font size="6">เพิ่ม/แก้ไขหมวดรายวิชา</font></label>					
				</div>
				
		<%
			////////////////// Add New Category ///////////////////
		%>		
			<div id="main-content-ac" align="center">
					<table border="0">	
					<form id="form1" name="form1" method="post" action="">		
						<tr style="font-size:24px">
							<td  height="50">
								<font size="5"><strong>ชื่อหมวด</strong></font>
								<label><font size="5" color="#FF0000">*</font></label>
							</td>
							<td  height="50">
								<input name="categoryName" type="text" required style="font-size:18px" />
							 
							</td>
						</tr>
							
						<tr style="font-size:24px">
							<td height="50">
								<font size="5"><strong>จำนวนหน่วยกิต</strong></font>
								<label><font size="5" color="#FF0000">*</font></label>		
							</td>
							<td height="50">
								<input name="Credit_category" type="text" required style="font-size:18px" />
														
							</td>
							<td>
								<center><input type="submit" value="add" name="add" class="buttonStyle"/></center>
							</td>							
						</tr>
					</form>	
					
				</table>
			</div>		
			<div id="main-content-ac" >						
						<br/>
						<center>
							<div class="CSSTableGenerator">							
								<table border="1">
									<tr style="font-size:22px">
									   <td>&nbsp;&nbsp;&nbsp;</td>
									    <td><center><strong>ชื่อหมวดวิชา</strong></center></td>
										<td><center><strong>จำนวนหน่วยกิต</strong></center></td>																						
										<td>เพิ่มกลุ่มวิชา</td>
										<td>ลบหมวดวิชา</td>
										<td>แก้ไขหมวดวิชา</td>
									  </tr>
									  
			    <%// TEST EDIT				    
					int categoryCount = 1;
			    	int i =0;
			    	int temp = 0;
			    	for(Category cat : category4 ) {			    		
				%>
										<tr style="font-size:18px" id="Curriculum<%=categoryCount%>">
										<form id="form<%=categoryCount%>" name="form<%=categoryCount%>" method="post" action="curriculum_modified_group.jsp">
												 
												<input type="hidden" id="GroupId" name="GroupId" value="none" /> 
												<input type="hidden" id="checkerCancel" name="checkerCancel" value="none" /> 
												
												<input type="hidden" id="flag" name="flag" value="1" />
												<input type="hidden" id="CategoryIdDelete<%=categoryCount%>" name="CategoryIdDelete<%=categoryCount%>" value="<%=cat.getCategoryId()%>" />
												<input type="hidden" id="checker" name="checker" value="none" />
												<input type="hidden" id="CurriculumId" name="CurriculumId" value="<%=cat.getCurriculumId()%>" />
												<input type="hidden" id="CategoryId" name="CategoryId" value="<%=cat.getCategoryId()%>" />  
												<td id="categoryCount" name="categoryCount" align="center">
													<%=categoryCount%>
												</td>
												
												<input type="hidden" id="categoryName" name="categoryName" value="<%=cat.getCategoryName()%>" />  
												<td id="categoryName<%=categoryCount%>" name="categoryName<%=categoryCount%>" align="center">
													<%=cat.getCategoryName()%>												
												</td>											
												<input type="hidden" id="Credit_category" name="Credit_category" value="<%=cat.getCredit()%>" /> 
												<td id="Credit_category<%=categoryCount%>" name="Credit_category<%=categoryCount%>" align="center">
													<%=cat.getCredit()%>
												</td>
												
												<input type="hidden" id="OHCE" name="OHCE" value="<%=curriculum4.get(i).getOHCE()%>" />
												<input type="hidden" id="ONEC" name="ONEC" value="<%=curriculum4.get(i).getONEC()%>" />  
												<input type="hidden" id="EngApp" name="EngApp" value="<%=curriculum4.get(i).getEngApp()%>" />
												<td><center><span title="เพิ่มข้อมูล"><input type="image" src="image/add_icon.png" height="30px" width="30px" /></span></center></td>
											</form>	
												<td><center><span title="ลบข้อมูล"><input type="image" src="image/delete_icon.png" height="30px" width="30px" onclick="deleteButton('<%=categoryCount%>')"/></span></center></td>										
										
										<form id="form<%=categoryCount%>" name="form<%=categoryCount%>" method="post" action="curriculum_category_modified_info.jsp">
												<input type="hidden" id="CurriculumId" name="CurriculumId" value="<%=category4.get(i).getCurriculumId()%>" />
												<input type="hidden" id="CategoryId" name="CategoryId" value="<%=category4.get(i).getCategoryId()%>" />												
												<input type="hidden" id="categoryName" name="categoryName" value="<%=category4.get(i).getCategoryName()%>" />
												<input type="hidden" id="Credit" name="Credit" value="<%=category4.get(i).getCredit()%>" /> 												
												
												<td><center><span title="แก้ไขข้อมูล"><input type="image" src="image/edit_icon.png" height="30px" width="30px"/></span></center></td>	
										</form>		
												
										</tr>
				
				<%
						categoryCount++;
						i++;

					}
			    	%>			  	
					</table>	
				</div>			
						</br></br>				
					</center>
					
					<div id="main-content-ac" align="center">
					<%if (course.size()==0){%>
							<form id="add_intern" name="add_intern" method="post" action="">
								
								<table border="0">
								<tr style="font-size:24px">
									<td height="50">
										<font size="5"><strong>การฝึกงาน</strong></font>
										<label><font size="5" color="#FF0000">*</font></label>
									</td>
									<td>
										<input type="text" name="search_box" autocomplete="off" placeholder="ex. egco1 and choose from dropdown lists" id="search_box" style="height: 25px; width: 400px; font-size:medium;" value="" list="namelist" onkeyup="search_name(this.value)" />
										<datalist id="namelist"></datalist>							
									</td>
									<td>
									<input type="hidden" id="CurriculumIdOLD" name="CurriculumIdOLD" value="<%=CurriculumIdOLD%>" />
									
										<input type="submit" value="add" name="add2"  class="buttonStyle"/>
									</td>
									
								</tr>
							</table>
							</form>	
				<%} %>
					<br>
					
						<%								
							    	for(int tempi= 0;tempi<category4.size();tempi++){
							    			temp = temp + category4.get(tempi).getCredit();
											System.out.println("                               c"+category4.size() );
											System.out.println("Total Current Credit:     "+ temp);	
									}
								
									if(tempchecker2.equals("TRUE") || course.size()==1){															
										/*int tempIntern = creditValue;
				  						temp = temp +  tempIntern;
				  						System.out.println("TEST TEMP IN TRUE:     "+ temp);*/
				  						checker4 = "added"; // check if intern was added 
				  						
				  						for(Course cou : course ) {	
				  						%>
					  						<form id="added_intern" name="added_intern" method="post" action="">
					  							<font size="5" color="green">ALREADY  HAS INTERNSHIP ! (credit: <%=course.get(0).getCredit()%>)</font>
					  							<br><br>
					  						</form>	
					  					<center>
					  						<table>					  						
					  							<tr style="font-size:22px">	
									  				<td><center><strong>รหัสวิชา</strong></center></td>
													<td><center><strong>ชื่อวิชา(EN)</strong></center></td>
													<td><center><strong>หน่วยกิต</strong></center></td>												
													<td><center>Delete</center></td>
												</tr>
					  					<form id="form" name="form" method="post" action="curriculum_delete_intern.jsp">	
					  						<tr style="font-size:18px" >
					  							<input type="hidden" id="CourseId" name="CourseId" value="<%=cou.getCourseId()%>" />
												<input type="hidden" id="CourseNameTH" name="CourseNameTH" value="<%=cou.getCourseNameTH()%>" />
												<input type="hidden" id="CourseNameEN" name="CourseNameEN" value="<%=cou.getCourseNameEN()%>" />
												<input type="hidden" id="CreditNew" name="CreditNew" value="<%=cou.getCredit()%>" />
												<input type="hidden" id="system" name="system" value="MOD" />
												
					  							<td align="center"><%=cou.getCourseId()%></td>
					  							<td align="center"><%=cou.getCourseNameEN()%></td>
					  							<td align="center"><%=cou.getCredit()%></td>
					  							<td><center><span title="ลบข้อมูล"><input type="image" src="image/delete_icon.png" height="30px" width="30px" /></span></center></td>				  							
											</tr>
										</form>
					  						</table>
					  						<br><br>
					  					</center>
					  					<%}
					  				}
								%>
							
							<table>
									<tr style="font-size:20px">
										<td height="50" width = "230">จำนวนหน่วยกิตรวมสูงสุดของหลักสูตร =   <%= Credit_cur%></td>
										<td height="50" width = "230">
									<%if(course.size()==1){ %>
										จำนวนหน่วยกิตรวมของทุกหมวดวิชา =   <%= temp%> + <%=course.get(0).getCredit() %> = <%=temp+course.get(0).getCredit()%>
									<%}else if(course.size()==0){ %>
										จำนวนหน่วยกิตรวมของทุกหมวดวิชา =   <%= temp%>
									<%} %>
									</td>
									</tr>
							</table>
							<br><br><font size="4" color="red">คำเตือน: ถ้ากดปุ่ม cancel ข้อมูลจะไม่ได้รับการบันทึก !</font><br><br>
					<table>
						<tr>
							<form id="form5" name="form5" method="post" action="">											
										<td><input type="submit" value="submit" name="SUBMIT" class="buttonStyle"/>	</td>
															
							</form>
							
							<form id="form6" name="form6" method="post" action="">											
										<td><input type="submit" value="cancel" name="cancel3" class="buttonStyle"/>	</td>
															
							</form>
						</tr>
					</table>
						
					</div>	
						<br><br><br>
					</div>
					<div style="clear: both;"></div>
						<div id="footer"></div>
			</div>	
						<div style="clear: both;"></div>	
	    </div>
  <%
 		String checkButton = request.getParameter("add");   
  		String checkButton2 = request.getParameter("SUBMIT");
  		String checkButton3 = request.getParameter("add2");
		String checkButton4 = request.getParameter("cancel3");
  		System.out.println(checkButton);
  		
if("cancel".equals(checkButton4)){	
			
			System.out.println("DELETE BUTTON");////////////try//////////
			request.setCharacterEncoding("UTF-8");
			try {			   
				connect.createStatement().executeUpdate("DELETE FROM `curriculum` "
						+" WHERE curriculum_id = '"+ CurriculumIdOLD + "'");
				
				String sql_curriculum = "DELETE FROM `curriculum` "
						+" WHERE curriculum_id = '"+ CurriculumIdOLD + "'";
						
				
				/* Log file */
				String log_user = strUser+" delete curriculum";
				Log.writeUserFile(log_user);
				Log.writeUserFile(sql_curriculum);
				
				connect.createStatement().executeUpdate("DELETE FROM `subject_category` "
						+" WHERE curriculum_id = '"+ CurriculumIdOLD + "'");
				
				String sql_category = "DELETE FROM `subject_category` "
						+" WHERE curriculum_id = '"+ CurriculumIdOLD + "'";						
				
				/* Log file */
				String log_user2 = strUser+" delete subject_category";
				Log.writeUserFile(log_user2);
				Log.writeUserFile(sql_category);
				
				
				System.out.println("delete sucess");////////////try//////////
%>							
				<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=curriculum_search.jsp">
<%
				
				} catch (SQLException e) {
					e.printStackTrace();
				}

	}
  		
  	// check save button is pressed
  	else	if("add".equals(checkButton3)){
  					request.setCharacterEncoding("UTF-8");
  					
  					String checker = request.getParameter("search_box");
  					String CurriculumIdModified = request.getParameter("CurriculumIdOLD");
  					if(checker == "") {
  						%><script>alert("กรุณาเลือกรายวิชาก่อนค่ะ");</script><%
  					}else{
  					
  						String course_name = new String(request.getParameter("search_box").getBytes("ISO8859_1"),"UTF-8");// Get info from search box
  						System.out.println("course_name :" + course_name);////////////////try////////////////
  						
  						String[] split = course_name.split(" , ");
  						System.out.println("split :" + split.length);////////////////try////////////////
  				if(split.length == 3)
  	  				{			
  						String courseId = split[0];			
  						System.out.println("courseId :" + courseId);////////////////try////////////////
  						
  						
  						
  						String courseNameEN = split[1];
  						System.out.println("courseNameEN :" + courseNameEN);////////////////try////////////////	
  						
  						String tempcredit = split[2];
  						System.out.println("tempcredit :" + tempcredit);////////////////try////////////////					
  						String[] split2 = tempcredit.split(" ");
  						
  						String credit2 = split2[0];
  						System.out.println("credit :" + credit);////////////////try////////////////
  						
  						String lecture = split2[2];
  						System.out.println("lecture :" + lecture);////////////////try////////////////
  						
  						String lab = split2[3];
  						System.out.println("lab :" + lab);////////////////try////////////////
  						
  						String selfLearn = split2[4];
  						System.out.println("selfLearn :" + selfLearn);////////////////try////////////////
  						
  						String details = "";				
  						System.out.println("details :" + details);////////////////try////////////////
  							
  						
  	////////////////////////////////////////////////////////////////////////////////
  						int checker22 = 0; //0 = not Duplicate, 1 = Duplicate
  						for(Course cou : course ) {	
  							System.out.println("Course DB:  "+cou.getCourseId());
  							System.out.println("Course Input:  "+courseId);
  						
  						if(cou.getCourseId().equals(courseId)){
  								System.out.println("Duplicate ID:  "+courseId);
  								System.out.println("////////////////////////////////////////////////////");
  								checker22 = 1;
  							}
  						}
  						int tempCredit2 = temp;				
  						int category_credit2 = Integer.parseInt(credit2);
  						int total2 = tempCredit2+category_credit2;
  						
  				if(total2 > Credit_cur){%>	
  					<script>alert("หน่วยกิตของหมวดวิชา_ไม่สามารถมากกว่า_หน่วยกิตของหลักสูตรได้");</script>				
  			<%					
  				}
  				else{	
  					if(checker22 == 0){
  							// insert data to database			
  							String sql_course = "INSERT INTO  `course`(`course_id`, `group_id`, `curriculum_id`, `course_name_th`, `course_name_en`, `credit`, `lecture_hour`, `lab_hour`, `self_learning_hour`, `detail`, `ohce_approved`, `onec_approved`)"
  							+ " VALUES ('"+ courseId +"', 0, "+ CurriculumIdModified +",' ', '"+ courseNameEN +"', "+ credit2 +", "+ lecture +", "+ lab +", "+ selfLearn +", '"+ details +"',"+ OHCE +", "+ ONEC +")";
  							System.out.println(sql_course);/////////////////////try///////////////////////////////
  							
  							session.setAttribute("checker", "TRUE");
  								try {		
  										// insert data into course 
  										connect.createStatement().executeUpdate("INSERT INTO  `course`(`course_id`, `group_id`, `curriculum_id`, `course_name_th`, `course_name_en`, `credit`, `lecture_hour`, `lab_hour`, `self_learning_hour`, `detail`, `ohce_approved`, `onec_approved`)"
  										+ " VALUES ('"+ courseId +"', 0, "+ CurriculumIdModified +",' ', '"+ courseNameEN +"', "+ credit2 +", "+ lecture +", "+ lab +", "+ selfLearn +", '"+ details +"', "+ OHCE +", "+ ONEC +")");
  							
  										session.setAttribute("value", credit2);
  										
  										/* Log file */
  										String log_user = strUser+" add course";
  										Log.writeUserFile(log_user);
  										Log.writeUserFile(sql_course);
  										
  										
  										%><script>alert("เพิ่มวืชาฝึกงานสำเร็จค่ะ")</script>
  										<meta HTTP-EQUIV="Refresh" CONTENT="1; URL=curriculum_category_modified.jsp"> 
  										<%					
  							} catch (SQLException e) {
  								e.printStackTrace();
  							}
  							
  					}else{
  							System.out.println("/////////////DUPLICATE FILE//////////////");
  							%><script>alert("มีวิชาฝึกงานอยู่แล้วค่ะ")</script><%
  						}
  					}	
  	  			}else{//if(split.length == 5)
					%><script>alert("ชื่อรายวิชาไม่ถูกต้องค่ะ กรุณาเลือกจากรายการที่มีเท่านั้น")</script><%
  				}
  			}
  		}
  				
  			else if("add".equals(checkButton)){ 
  				request.setCharacterEncoding("UTF-8");
  				//Temp
  					String tempCredit_category = request.getParameter("Credit_category");
  					String tempcategoryName =  new String(request.getParameter("categoryName").getBytes("ISO8859_1"),"UTF-8");
  				
 //////////////////////////////CHECK IF INPUT WERE SPECIAL CHARACTERS> //////////////////////
					Pattern regex = Pattern.compile("[$&+,:;=?@#^*)(|!%]");
					Matcher matchertempCredit_category = regex.matcher(tempCredit_category);
					Matcher matchertempcategoryName = regex.matcher(tempcategoryName);
								
		if (matchertempCredit_category.find() || matchertempcategoryName.find()){
		%>
			<script language="javascript"> alert("ข้อมูลไม่ถูกต้อง โปรดใช้ตัวเลขหรือตัวอักษรเท่านั้น");	</script>
		<%}else{  					
				boolean checker = tempCredit_category.matches("[-+]?\\d+(\\.\\d+)?");
				System.out.println("checker: "+checker);		
				//Check if name or credit are zero or not
  				if(tempcategoryName.equals("") || tempCredit_category.equals("")){
  					if(tempcategoryName.equals("") ){%>
					<script>alert("กรุณาใส่ชื่อหมวดวิชา");</script>
					<%}
  					else if(tempCredit_category.equals("") ){%>
						<script>alert("กรุณาใส่จำนวนหน่วยกิต");</script>
					<%}
  				}if(checker){
  					int tempCredit = temp;				
  					int category_credit = Integer.parseInt(request.getParameter("Credit_category"));
  					String CategoryName = new String(request.getParameter("categoryName").getBytes("ISO8859_1"),"UTF-8");
  					int total = tempCredit+category_credit;
  					
  					
  					if(total > Credit_cur){	%>	
  						<script>alert("หน่วยกิตของหมวดวิชา_ไม่สามารถมากกว่า_หน่วยกิตของหลักสูตรได้");</script>				
  	<%				
  		
  					}else{	
  					 		try {	
  					 			int Credit = Integer.parseInt(request.getParameter("Credit_category"));				
  								System.out.println("Credit: "+ Credit);	
  								
  								
  								  PreparedStatement pstmt = connect.prepareStatement("INSERT INTO `subject_category`(`category_name`, `curriculum_id`, `credit`)" 
  											+ " VALUES ('"+ CategoryName +"','"+ CurriculumIdOLD +"','"+ Credit +"')" , Statement.RETURN_GENERATED_KEYS);
  								 	pstmt.executeUpdate();    					
  								 	
  								 	
  								 	String sql_category = "INSERT INTO `subject_category`(`category_name`, `curriculum_id`, `credit`)" 
  											+ " VALUES ('"+ CategoryName +"','"+ CurriculumIdOLD +"','"+ Credit +"')";
											
									
									/* Log file */
									String log_user = strUser+" add subject_category";
									Log.writeUserFile(log_user);
									Log.writeUserFile(sql_category);
  	%>
  								<script language="javascript"> alert("บันทึกหมวดวิชาสำเร็จ");</script>	
  								<meta HTTP-EQUIV="Refresh" CONTENT="1; curriculum_category_modified.jsp"> 
  	<%
  								} catch (SQLException e) {
  									System.out.println("Error At Phase 1 Add CurriID:"+e);
  									e.printStackTrace();
  								}
  						}
  				}else{//checker%>
					<script language="javascript"> alert("กรุณาใส่หน่วยกิตด้วยตัวเลขค่ะ");</script>	
				<%}
		}//else special
			}else if("submit".equals(checkButton2)){
			if(tempchecker2.equals("TRUE") || course.size()==1){
				for(Course cou : course ){
					int tempIntern = cou.getCredit();
					int finalCredit = temp+tempIntern;
					System.out.println("finalCredit:"+finalCredit);
					
				if(finalCredit < Credit_cur){	
					%><script>alert("กรุณาใส่หน่วยกิตให้ครบตามที่กำหนดไว้");</script><%
				}if(finalCredit > Credit_cur){	%>	
						<script>alert("หน่วยกิตของหมวดวิชาไม่สามารถมากกว่า_หน่วยกิตของหลักสูตรได้\nกรุณาแก้ไขหรือลบหมวดวิชาอื่นๆ");</script>				
<%				
				}if(finalCredit == Credit_cur){%>
									
					<script language="javascript"> alert("บันทึกข้อมูลหมวดวิชาสำเร็จ");</script>						
					<meta HTTP-EQUIV="Refresh" CONTENT="1; URL=curriculum_modified_home.jsp">
			<%}}
			}else{
				%><script>alert("กรุณาใส่วิชาฝึกงาน");</script><%
			}
			}
					
connect.close();
	%> 
</body>
</html>